package com.cty.dijkstra;

import java.util.Arrays;

public class VisitedVertex {
    int[] already_arr;
    int[] dis;
    int[] pre_visited;
    public VisitedVertex(int index,int len) {
        already_arr = new int[len];
        dis = new int[len];
        pre_visited = new int[len];
        Arrays.fill(dis,65535);
        already_arr[index] = 1;
        dis[index] = 0;
    }

    public boolean in(int index) {
        return already_arr[index] == 1;
    }

    public void updateDis(int index,int len) {
        dis[index] = len;
    }

    public void updatePre(int pre,int index) {
        pre_visited[index] = pre;
    }

    public int getDis(int index) {
        return dis[index];
    }

    public int updateArr() {
        int min = 65535, index = 0;
        for (int i = 0; i < already_arr.length;i++) {
            if (already_arr[i] == 0 && dis[i] < min) {
                min = dis[i];
                index = i;
            }
        }
        already_arr[index] = 1;
        return index;
    }

    public void showRes() {
        for (int i : dis) {
            System.out.printf(i + " ");
        }
    }
}
